package com.mathassistant.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.IntegerBox;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.mathassistant.client.presenter.ExerciseEditPresenter.Display;
import com.mathassistant.shared.ExerciseDTO;

public class ExerciseEditView extends Composite implements Display{

	private static ExerciseEditViewUiBinder uiBinder = GWT
			.create(ExerciseEditViewUiBinder.class);
	@UiField Anchor inputQuestionAnchor;
	@UiField Anchor inputAnwser1;
	@UiField Anchor inputAnwser2;
	@UiField Anchor inputAnwser3;
	@UiField Anchor inputAnwser4;
	@UiField IntegerBox correctAnwserTextbox;
	@UiField Button saveButton;
	@UiField Button closeButton;
	@UiField HTML displayQuestionHTML;
	@UiField HTML displayAnwser1HTML;
	@UiField HTML displayAnwser2HTML;
	@UiField HTML displayAnwser3HTML;
	@UiField HTML displayAnwser4HTML;

	interface ExerciseEditViewUiBinder extends
			UiBinder<Widget, ExerciseEditView> {
	}

	public ExerciseEditView(ExerciseDTO exercise) {
		initWidget(uiBinder.createAndBindUi(this));
		inputQuestionAnchor.addStyleName("input-anchor");
		inputAnwser1.addStyleName("input-anchor");
		inputAnwser2.addStyleName("input-anchor");
		inputAnwser3.addStyleName("input-anchor");
		inputAnwser4.addStyleName("input-anchor");
		saveButton.addStyleName("dlgAbout-button");
		closeButton.addStyleName("dlgAbout-button");
		
		if(exercise != null)
			this.setData(exercise);
	}

	@Override
	public HasClickHandlers getQuestionAnchor() {
		// TODO Auto-generated method stub
		return this.inputQuestionAnchor;
	}

	@Override
	public HasClickHandlers getAnswer1Anchor() {
		// TODO Auto-generated method stub
		return inputAnwser1;
	}

	@Override
	public HasClickHandlers getAnswer2Anchor() {
		// TODO Auto-generated method stub
		return inputAnwser2;
	}

	@Override
	public HasClickHandlers getAnswer3Anchor() {
		// TODO Auto-generated method stub
		return inputAnwser3;
	}

	@Override
	public HasClickHandlers getAnswer4Anchor() {
		// TODO Auto-generated method stub
		return inputAnwser4;
	}

	@Override
	public HasHTML getQuestionHtml() {
		// TODO Auto-generated method stub
		return displayQuestionHTML;
	}

	@Override
	public HasHTML getAnswer1Html() {
		// TODO Auto-generated method stub
		return displayAnwser1HTML;
	}

	@Override
	public HasHTML getAnswer2Html() {
		// TODO Auto-generated method stub
		return displayAnwser2HTML;
	}

	@Override
	public HasHTML getAnswer3Html() {
		// TODO Auto-generated method stub
		return displayAnwser3HTML;
	}

	@Override
	public HasHTML getAnswer4Html() {
		// TODO Auto-generated method stub
		return displayAnwser4HTML;
	}

	@Override
	public HasClickHandlers getSaveButton() {
		// TODO Auto-generated method stub
		return saveButton;
	}

	@Override
	public HasClickHandlers getCloseButton() {
		// TODO Auto-generated method stub
		return closeButton;
	}

	@Override
	public void setData(ExerciseDTO exercise) {
		// TODO Auto-generated method stub
		
		this.correctAnwserTextbox.setText(Integer.toString(exercise.getAnswer()));
		this.displayQuestionHTML.setHTML(exercise.getQuestion());
		this.displayAnwser1HTML.setHTML(exercise.getChooses().get(0));
		this.displayAnwser2HTML.setHTML(exercise.getChooses().get(1));
		this.displayAnwser3HTML.setHTML(exercise.getChooses().get(2));
		this.displayAnwser4HTML.setHTML(exercise.getChooses().get(3));
	}

	@Override
	public HasValue<Integer> getCorrectAnsIntBox() {
		// TODO Auto-generated method stub
		return correctAnwserTextbox;
	}

}
